/** @jsxImportSource @emotion/react */
import * as React from "react";
import {OriginalViewProps,} from "../../common/base";
import {
    config几何尺寸, config制动距离, config观测数据, config设备概况, EntranceSetup, MeasureCalc, tailZj观测, tail几何, tail制动, tail速度,
} from "./orcBase";
import {createItem,} from "../../common/eHelper";
import {useRecordList} from "../../hook/useRecordList";
import {setupItemAreaRoute} from "./orcIspConfig";
import {EditStorageContext} from "../../StorageContext";
import {Text, useTheme} from "customize-easy-ui-component";
import {ItemInstrumentTable} from "../../common/Instrument";
import {FrontCover, ItemConclusion} from "../../mobilecr/editorIN";
import {SiteConditionSund,} from "../../elevator/sundryDj/editor";
import {GenCode} from "../../common/GenCode";
import {ActionMapItem} from "../../common/ActionMapItem";
import {config记录} from "./FormatOriginal";
import {RecheckEditor} from "../../common/editor";
import {DeviceSurveyD} from "../../crane/editor";
import {Thickness} from "../../tower/craneJj/editThicknes";
import {WitnessCr3Tower} from "../../tower/editorJj";
import {MeasureCritMem} from "../../hook/useMeasure";
import {Braking} from "../../gantry/portalJj/Braking";
import {DoorGap} from "./DoorGap";
import {config运行速度, MoveSpeednoAv} from "./MoveSpeednoAv";
import {Description} from "./Description";
import {areaCapacity, reachBeyond} from "./repView";
import {MagneticLeak} from "../../gantry/portalJj/MagneticLeak";

const defFrameM={
    'CmnTowerCrane': `{ "mg":2, "dcl":"C","cl":"C",
      "sk":[{"no":"5", "r":11,"s":1 ,"bs":[10,11], "vx":1}
     ]}`,
};
export const default见证=[{no:'ZLQR',ti:'资料审查确认单'},{no:'ZJBG',ti:'简易升降机施工自检报告'}];
export const default记事=[{nm:'检验意见通知书'},];
export const tItems现场=[
    ['1、动力源、环境温度、海拔高度、风速',{f:'T',
        N: <Text>1、试验的动力源、环境温度、海拔高度、风速符合标准和设计要求。</Text>},],
    ['2、不得有易燃、易爆以及腐蚀性',{f:'y',
        N: <Text>2、检验现场不得有易燃、易爆以及腐蚀性气体。</Text>},],
];

const recordPrintList =[
    createItem('Entrance', <EntranceSetup/>),
    createItem('FrontCover', <FrontCover/>),
    createItem('Instrument', <ItemInstrumentTable label={'一、主要检验仪器设备性能检查'} />),
    createItem('Survey', <DeviceSurveyD config={config设备概况} label={'二、设备概况'}/>),
    createItem('Item', null),
    createItem('Conclusion', <ItemConclusion startd  label={'四、 结论'} nxtstyp={'检验'}/>),
    createItem('Witness', <WitnessCr3Tower label={'五、技术资料和工作见证材料 六、记事 七、备注'} titles={['五','六','七']} defWitn={default见证} defNote={default记事}>
                        <></>
                        <>注：本备注栏的内容在检验报告附件的备注栏内体现。</>
                    </WitnessCr3Tower>),
    createItem('Measure', <MeasureCalc config={config观测数据} mem='观测备注' children={tailZj观测} label={'附录1 观测值及测量结果记录表'}/>),
    createItem('Gap', <DoorGap label='附录2：C5 门间隙、层门净高度、门锁啮合长度检验记录'/>),
    createItem('Geometric', <MeasureCritMem allowableV config={config几何尺寸} mem='几何备注' label={'附录3：C3.6主要几何尺寸观测值及测量结果记录表（适于改造监检）'}
                                           children={tail几何}/>),
    createItem('Thickness', <Thickness label={'附录4：C3.7.3 主要受力结构件断面有效厚度观测值及测量结果记录'}/>),
    createItem('MoveSpeed', <MoveSpeednoAv config={config运行速度} children={tail速度} label={'附录5：C4.3.2.1各机构运行速度记录表'}/>),

    createItem('Braking', <Braking config={config制动距离} children={tail制动} label={'附录6：C4.3.2.2起升机构制动距离记录表'}/>),
    createItem('AreaCapacity', <Description children={areaCapacity} label={'附录 7：货厢面积和起重量'}/>),
    createItem('MagneticLeak', <MagneticLeak label={'附录8：C4.9.8.1漏磁检查记录表'}/>),

    createItem('SiteCondition', <SiteConditionSund config={tItems现场} label={'附录9：现场检验条件确认'}/>),
    createItem('ReachBeyond', <Description children={reachBeyond} label={'附录10 越过保护结构触及'}/>),
    createItem('ReCheck', <RecheckEditor  label={'附录11 检验不合格项目内容'} setup={setupItemAreaRoute}/>),
];
if(process.env.REACT_APP_TEST==='true')  recordPrintList.splice(0,0,createItem('GenCode', <GenCode type='CmnTowerCrane'
                                             frameMod={defFrameM}/>));


export const OriginalView=
  React.forwardRef((
    { action,  verId, repId='', rep,}
    :OriginalViewProps, ref
  ) => {
    const context =React.useContext(EditStorageContext);
    if(context == null)    throw new Error("EditStorageContext没有提供");
    const {storage, } =context;
    const theme = useTheme();
    const witnessNos =React.useMemo(() => {
      return storage.见证表?.map((a:any, i:number) => a && a.no);
    }, [storage.见证表]);
    const recordPrintListNow =React.useMemo(() => {
      config记录[2].l=witnessNos;     //动态的 工作见证 列表注入：
      let routeAreas=[] as any[];
      const impressionismAs =setupItemAreaRoute({rep, orc:storage, theme});
      let extendTags =Reflect.ownKeys(impressionismAs) as string[];
      const oldItCount=recordPrintList.length;
      let prevpos=0;
      for(let p=0; p<oldItCount; p++){
        if(extendTags.indexOf(recordPrintList[p].itemArea)>=0){     //需要展开 扩充的标签
            routeAreas=routeAreas.concat(recordPrintList.slice(prevpos,p));
            const itemConfigs= impressionismAs?.[recordPrintList[p].itemArea];
            let seq = 0;
            let moreItems = [] as any;
            itemConfigs.forEach((area, x) => {
              seq += 1;
              const rowHead =<ActionMapItem key={seq} alone={false} editAreasConf={itemConfigs}
                                                    index={x} sureD editIts={config记录} />;
              moreItems.push(createItem(area.tag, rowHead));
            });
            routeAreas=routeAreas.concat(moreItems);
            prevpos=p+1;
        }
      }
      routeAreas=routeAreas.concat(recordPrintList.slice(prevpos));
      return routeAreas;
    }, [witnessNos, verId, repId,rep, storage?._Oitems, theme]);

    const {list}=useRecordList(ref,rep,recordPrintListNow,action,verId);
    return <React.Fragment>
      {list}
        {/*      <Button  intent="primary"
                   onPress={(e) => { handleSubmit!();
                   }}
          >送打印转换器
          </Button>*/}
    </React.Fragment>;
  } );
